package com.fpf.springboot.config;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

@Configuration
public class RedisConfig {
	
	@Value("${spring.redis.cluster.nodes}")
	private String clusterNodes;
	
	@Bean
	public JedisCluster getJedisCluster() {
		String[] nodes = clusterNodes.split(",");
		Set<HostAndPort> hostAndPost=new HashSet<>();
		for(String node:nodes) {
			String[] arr = node.split(":");
			hostAndPost.add(new HostAndPort(arr[0], Integer.parseInt(arr[1])));
		}
		
		JedisCluster jedisCluster=new JedisCluster(hostAndPost);
		return jedisCluster;
	}
}
